package com.study.rabbitmq.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class MqttProviderCallBack implements MqttCallback {

    @Autowired
    private MqttConfig mqttConfig;

    /**
     * 与服务器断开的回调
     */
    @Override
    public void connectionLost(Throwable cause) {
        cause.printStackTrace();
        log.error("serverClientId:{}, 与服务器断开连接:{}", mqttConfig.getServerClientId(), cause.getMessage());
    }


    /**
     * 消息到达的回调
     */
    @Override
    public void messageArrived(String topic, MqttMessage message) throws Exception {
        log.info("MqttProviderCallBack topic:{}, message:{}", topic, message.getPayload());
    }

    /**
     * 消息发布成功的回调
     */
    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {

    }
}
